package com.example.list;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod;
import android.text.method.ReplacementTransformationMethod;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.EditText;

import com.example.utils.ToastUtil;

public class TextviewClickActivity extends AppCompatActivity {

    private EditText et_pwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_textview_click);
        et_pwd = (EditText) findViewById(R.id.et_pwd);
//        et_pwd.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
        et_pwd.setTransformationMethod(MPasswordTransformationMethod.getInstance());


//        spinnerableString();

    }
    void spinnerableString(){

        String[] result = {"为人民服务","毛泽东"};
        String data = "为人民服务,毛泽东".replace(",", "\n");
        SpannableString spannableString = new SpannableString(data);
        spannableString.setSpan(new AbsoluteSizeSpan(12, true), 0, result[0].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#F74850")), result[0].length(), data.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(new AbsoluteSizeSpan(12, true), result[0].length(), data.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        et_pwd.setText(spannableString);
    }

    public void tv1(View view) {
        ToastUtil.showToast(et_pwd.getText().toString());

    }
    public static class WordReplacement2 extends ReplacementTransformationMethod {
        String strWord = null;
        @Override
        protected char[] getOriginal() {
            //循环ASCII值 字符串形式累加到String
            for (char i = 0; i < 256; i++) {
                strWord += String.valueOf(i);
            }
            //strWord转换为字符形式的数组
            char[] charOriginal = strWord.toCharArray();
            return charOriginal;
        }
        @Override
        protected char[] getReplacement() {
            char[] charReplacement = new char[255];
            //输入的字符在ASCII范围内，将其转换为'·'
            for (int i = 0; i < 255; i++) {
                charReplacement[i] = '·';
            }
            return charReplacement;
        }
    }
}